﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using RN.ERP.BLL;
using RN.ERP.DTO;
using System.Web.Services;
using Newtonsoft.Json;

namespace RN.ERP.Web.Material.MaterialProperty
{
    public partial class List : BasePage
    {
        MaterialBLL bll = new MaterialBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        public string GetMPCode(object id)
        {
            return string.Empty;
        }

        public string GetMPName(object id)
        {
            return string.Empty;
        }
        public string GetMPMemo(object id)
        {
            return string.Empty;
        }

        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            ////绑定数据源
            BindData();
        }

        private void BindData()
        {
            RadGridList.AllowCustomPaging = true;
            int pageCount = RadGridList.CurrentPageIndex;
            int pageSize = RadGridList.PageSize;
            int count = 0;
            List<DTO.MateProperty> properties = bll.GetMaterialProperties(
                pageCount,
                pageSize,
                out count);
            RadGridList.VirtualItemCount = count;
            RadGridList.DataSource = properties;
        }

        [WebMethod]
        public string DelKC(object id)
        {
            ////删除考场
            int kcId = 0;
            int.TryParse(id.ToString(), out kcId);
            DTO.OperationResult ret = bll.DeleteMaterialProperty(kcId);
            return JsonConvert.SerializeObject(new { Message = ret.Message });
        }

        protected void RadGridList_ItemCommand(object sender, GridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "del":
                    int kcId = 0;
                    int.TryParse(e.CommandArgument.ToString(), out kcId);
                    DTO.OperationResult result = bll.DeleteMaterialProperty(kcId);
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "", "$.ligerDialog.warn('" + result.Message + "','',RefreshWin);", true);
                    break;
                case "go":
                    string id = e.CommandArgument.ToString();
                    Response.Redirect("mplist.aspx?id=" + id);
                    break;
                default:
                    break;
            }
        }
    }
}